home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr36 / gapcdr6.zip / CDOOR.ZIP / CDOOR.C < prev    next >
C/C++ Source or Header  |  1993-04-19  |  14KB  |  336 lines

  1. /*
  2.     Copyright (C) 1989-1993 The GAP Development Company
  3.  
  4.     All Rights Reserved
  5.  
  6.  
  7.     CDOOR.C
  8.  
  9.     Demonstration program for GAPCDR
  10.  
  11.  
  12.     Microsoft
  13.  
  14.     To compile : cl /c /FPa /Os /Og /Ob0 cdoor.c
  15.     To link    : link cdoor,,NUL.MAP,+gapcdrs
  16.  
  17.     ----------------------------------------------------------
  18.  
  19.     Borland
  20.  
  21.     With Borland, YOU have to tell it which of its OWN
  22.     OBJ and LIB files to link in. It isn't smart enough to
  23.     KNOW which ones are required.
  24.  
  25.     Be sure that C0S.OBJ is linked first and that you NAME
  26.     the EXE file (otherwise it will be named C0S.EXE.
  27.  
  28.     To compile : bcc -ms -O -Z -d -c cdoor.c
  29.     To link    : tlink c0s+cdoor,cdoor.exe,NUL.MAP,+gapcdrbs+cs
  30.  
  31.  
  32.     Program will need access to CDOOR.CNF and DOOR.SYS
  33.  
  34. */
  35.  
  36. #pragma check_stack(off)                  // we dont need stack checking
  37.                                           // IMPORTANT !!
  38. #pragma optimize("b0celt",on)             // Compiler optimizations for MSC
  39.  
  40. #include <stdio.h>                        // C standard header file
  41. #include <dos.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44.  
  45.    /***********************************************************************/
  46.    /*  Before doing ANYTHING else, include the following files.           */
  47.    /***********************************************************************/
  48.  
  49. #pragma pack(1)                           // All structures must be packed
  50.                                           // IMPORTANT !!
  51.  
  52. #include "compiler.h"                     // defines compiler being used
  53. #include "gapcdr.h"                       // header file for GAPCDR
  54.  
  55.  
  56.    /***********************************************************************/
  57.    /*  Declare any global variables                                       */
  58.    /***********************************************************************/
  59.  
  60.    char anystring1 [250];                 // global garbage collector
  61.  
  62.    // We are placing our Menu inside the program.
  63.    // It can just as easily be a file that we would display.
  64.    // Notice that the Menu contains embedded ANSI codes.
  65.    // Also notice that we don't have a non-color version of the Menu.
  66.    // This is because if the caller is in mono mode, GAPCDR will filter
  67.    // the ANSI codes. It is important to realize that if you have ONLY
  68.    // a color version of a Menu or Display file, that the Menu contain
  69.    // ONLY ANSI color sequences. It cannot contain any other ANSI 
  70.    // sequences such as cursor movement commands. Notice that our
  71.    // Menu uses actual 'spaces' and no cursor sequences. If the Menu
  72.    // contained cursor movement commands and the caller is in non-color
  73.    // mode, the ANSI driver will remove the ANSI sequences (which includes
  74.    // the cursor movement commands) and the screen will not display
  75.    // correctly.
  76.  
  77.    char *menug [] =
  78.       {
  79.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  80.       "          ▒▒▒▒▒▒▒▒┌──────────────────────────────────────┐▒▒▒▒▒▒▒▒▒▒",
  81.       "          ▒▒▒▒▒▒▒▒│              Main Menu               │▒▒▒▒▒▒▒▒▒▒",
  82.       "          ▒▒▒▒▒▒▒▒└──────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒",
  83.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  84.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  85.       "          ▒▒▒▒▒▒▒▒┌──────────────────────────────────────┐▒▒▒▒▒▒▒▒▒▒",
  86.       "          ▒▒▒▒▒▒▒▒│  [C]olor               [T]op Scores  ▒▒▒▒▒▒▒▒▒▒",
  87.       "          ▒▒▒▒▒▒▒▒│  [D]os Window          [S]how File   ▒▒▒▒▒▒▒▒▒▒",
  88.       "          ▒▒▒▒▒▒▒▒│  [X]code Example       [A]NSICMD's   ▒▒▒▒▒▒▒▒▒▒",
  89.       "          ▒▒▒▒▒▒▒▒│  [P]age Sysop          [Q]uit        ▒▒▒▒▒▒▒▒▒▒",
  90.       "          ▒▒▒▒▒▒▒▒└──────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒",
  91.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  92.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  93.       "\0"
  94.       };
  95.  
  96.  
  97.    // declare functions
  98.  
  99.    static void __pascal __near dos_window(short how);
  100.  
  101.  
  102.    /***********************************************************************/
  103.    /*  Begin main line code here                                          */
  104.    /***********************************************************************/
  105.  
  106. void main(void)
  107. {
  108.    short oldbell;                         // status of page bell flag
  109.    char **menu;                           // pointer to menu arrays
  110.    char response [80];                    // for getting responses
  111.    char prompt   [80];                    // for the prompt line
  112.  
  113.    FILE *doorcnf;                         // file pointer for cnf file
  114.  
  115.    // remember screen attributes for the DOS Window
  116.  
  117.    get_attr();                            // remember screen attribs
  118.  
  119.  
  120.    /***********************************************************************/
  121.    /*  Before doing ANYTHING else, initialize the door with the following */
  122.    /*  two function calls.                                                */
  123.    /*  Then, if you have any configuration options, read them in and then */
  124.    /*  close the file.                                                    */
  125.    /*  Note that we are hardcoding the name of the configuration file.    */
  126.    /*  Normally, this is passed as a command line parameter so you would  */
  127.    /*  call read_cnf like this :  doorcnf = read_cnf(argv[1]);            */
  128.    /***********************************************************************/
  129.  
  130.    doorcnf = read_cnf("CDOOR.CNF");       // read door configuration file
  131.    init_door();                           // initialize the door
  132.  
  133.    fclose(doorcnf);                       // we dont have any configuration
  134.                                           // options so we will just close
  135.  
  136.  
  137.    /***********************************************************************/
  138.    /*  Lets now build some menus all at once.                             */
  139.    /*  These menus were created with an ANSI editor.  This is perhaps the */
  140.    /*  fastest and easiest way to create menus.                           */
  141.    /***********************************************************************/
  142.  
  143.    do
  144.       {
  145.       // Format the prompt
  146.  
  147.       time_left();                        // get # of mins left
  148.  
  149.       sprintf(prompt,"\r\n%s[%s%d mins%s] Main Command : ",A_YELLOW,
  150.               A_BRED,timeleft,A_YELLOW);
  151.  
  152.       clear_scrn();                       // first clear the screen
  153.  
  154.       nl(2);                              // do a couple of blank lines
  155.  
  156.       menu = menug;                       // set pointer to our menu
  157.  
  158.       while (**menu)                      // now show the menu
  159.          show_mess(*menu++,NO,YES);
  160.  
  161.       show_mess(prompt,NO,NO);            // show the prompt
  162.  
  163.       empty(response,1);                  // initialize response
  164.       get_string(response);               // get user input
  165.  
  166.       switch (response[0])
  167.          {
  168.          case 'C' :                       // toggle color
  169.             if (color)                    // if in color already
  170.                color = 0;                 // turn color flag off
  171.             else                          // otherwise
  172.                color = 1;                 // turn it on
  173.  
  174.             fix_color();                  // tell ANSI driver what we did
  175.             break;
  176.  
  177.          case 'D' :                       // DOS Window
  178.             // show message on local screen so they know how to get
  179.             // back to program
  180.  
  181.             nl(1);
  182.             lputs(A_BWHITE);
  183.             lputs("                      Type 'Exit' to return to program");
  184.  
  185.             dos_window(0);                // make a DOS window
  186.             system("COMMAND");            // shell to DOS
  187.             dos_window(1);                // remove the DOS window
  188.             break;
  189.  
  190.          case 'P' :                       // page the sysop
  191.             oldbell = bell;               // remember original setting
  192.             bell = 1;                     // turn page bell on
  193.             pagesysop();                  // go page the sysop
  194.             bell = oldbell;               // restore setting
  195.             break;
  196.  
  197.          case 'T' :                       // show the scoreboard
  198.             read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
  199.             
  200.             // add name to score board file
  201.  
  202.             strcpy(response,username);    // remember user name
  203.  
  204.             ansi(A_YELLOW);               // set a color
  205.  
  206.             show_mess("Please Enter Your Name : ", NO,NO);
  207.  
  208.             empty(username,30);           // initialize string
  209.             get_string(username);         // go get a name
  210.  
  211.             if (username[0] != 0)         // if name was entered
  212.                {
  213.                write_score("CDOOR.DAT",20220L);   // write the score
  214.  
  215.                ansi(A_BWHITE);            // set a color
  216.                nl(1);
  217.                show_mess("You are now a Top 10 Player!",NO,YES);
  218.                nl(1);
  219.                pause();
  220.                read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
  221.                }
  222.  
  223.             strcpy(username,response);    // restore name
  224.  
  225.             break;
  226.  
  227.          case 'A' :
  228.             clear_scrn();                 // clear local and remote screens
  229.             show_file("ANSICMD");         // pass base part of filename
  230.             pause();                      // make sure they've seen it
  231.             break;
  232.  
  233.          case 'X' :
  234.             clear_scrn();                 // clear local and remote screens
  235.             show_file("XCODES");          // pass base part of filename
  236.             pause();                      // make sure they've seen it
  237.             break;
  238.  
  239.          case 'S' :                       // show file
  240.             show_file("WELCOME");         // pass base part of filename
  241.             pause();                      // make sure they've seen it
  242.             break;
  243.  
  244.          case 'Q' :                       // quit
  245.             break;
  246.          }
  247.       }
  248.    while (response[0] != 'Q');
  249.  
  250.    leave(0);                              // must exit properly!
  251. }
  252.  
  253.    // makes or removes a DOS Window
  254.    // 0 = make window
  255.    // 1 = remove window
  256.  
  257.    // Our DOS window is 14 rows by 64 columns (including border) - 1792 bytes
  258.  
  259.    // NOTE: The program can NOT, under any circumstance, exit or abort 
  260.    // while the DOS window is being displayed. If it does, the computer
  261.    // will crash. This means that while the window is up, there can be
  262.    // NO input or output using GAPCDR since if carrier is dropped, GAPCDR
  263.    // will shut down, and the BIOS trap will still be operating. The end
  264.    // result is a locked up computer the next time a program is run
  265.  
  266.  
  267.    static unsigned short __near dseg = 0; // DOS stores segment address here
  268.  
  269.    static char __near border [] =
  270.       {
  271.       "──────────────────────────────────────────────────────────────"
  272.       };
  273.  
  274.  
  275. static void __pascal __near dos_window(short how)
  276. {
  277.    short r;
  278.  
  279.    if (!how)                              // set up the screen
  280.       {
  281.       // # of bytes to allocate is 
  282.       // (((cols * 2) * rows) / 16) + 2 (for good measure)
  283.  
  284. #ifdef TC
  285.       if ((allocmem(114,&dseg)) != -1)     // get memory to hold screen
  286. #else
  287.       if ((_dos_allocmem(114,&dseg)) != 0) // get memory to hold screen
  288. #endif
  289.          {                                // can't
  290.          dseg = 0;                        // NULL out pointer
  291.          return;                          // return now
  292.          }
  293.  
  294.       lputs("s");                       // remember cursor position for ANSI
  295.       save_screen(3,8,16,71,dseg);        // save underlying window
  296.       normal = 15;                        // Bright White border
  297.  
  298.       crscur = 0x0308;                    // cursor to row 3, column 8
  299.       sprintf(anystring1,"┌%s┐",border);
  300.       lputs(anystring1);                  // show top border
  301.  
  302.       for (r = 4; r < 17; r++)            // display sides of window
  303.          {
  304.          crscur = 0x0008 + (256 * r);     // next line
  305.          lputc('│');                      // left side
  306.          crscur += 62;                    // position cursor
  307.          lputc('│');                      // right side
  308.          }
  309.  
  310.       crscur = 0x1008;                    // cursor to row 16, column 8
  311.       sprintf(anystring1,"└%s┘",border);
  312.       lputs(anystring1);                  // show top border
  313.  
  314.       // set up the BIOS trap so that the cursor stays inside of the
  315.       // window
  316.  
  317.       set_int10();                        // set up BIOS handler
  318.       set_cord(4,9,15,70);                // set window co-ordinates (inside dimensions)
  319.       set_attr(14,1);                     // set window attributes (yellow on blue)
  320.       cls_all();                          // clear the window
  321.       }
  322.    else if (how && dseg != 0)             // remove the screen
  323.       {
  324.       rest_int10();                       // reset BIOS handler
  325.  
  326.       restore_screen(3,8,16,71,dseg);     // restore underlying window
  327. #ifdef TC
  328.       freemem(dseg);                      // free memory
  329. #else
  330.       _dos_freemem(dseg);                 // free memory
  331. #endif
  332.       dseg = 0;                           // NULL out pointer
  333.       lputs("u");                       // restore cursor
  334.       }
  335. }
  336.